// License Notification
//======================================================
// Copyright (c) 2010 Channel Intelligence Inc.
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// ======================================================




using System;

namespace CIP4.Item
{
    [AttributeUsage(AttributeTargets.Class)]
    public class CIP4ItemAttribute: Attribute
    {
        public static CIP4ItemAttribute GetAttribute(Type fromType)
        {
            object[] objects = fromType.GetCustomAttributes(typeof(CIP4ItemAttribute), true);
            if (objects.Length > 0)
                return (CIP4ItemAttribute)objects[0];
            return null;
        }

        /// <summary>
        /// This is the name that will be used in building the xml representation of the item. 
        /// Bt default this is the same as the name of the type the attribute is attached to
        /// Use this property if you have more than one CIP4 collection of the same type.
        /// </summary>
        public string ActualName { get; set; }

        /// <summary>
        /// This is the collection that instances of this account will be found in and saved to
        /// </summary>
        public string Collection { get; set; }

        /// <summary>
        /// If true - all properties in the class will be used in serialization and deserialization
        /// </summary>
        public bool AddAllProperties { get; set; }

        /// <summary>
        /// If supplied, this will be used as the domain part of the version namespaces used to identify
        /// the version of serialized objects - for example if CersionDomain is foo.com the CIPl item namespace will be
        ///     http://foo.com/CIPlItem1.xsd
        /// </summary>
        public string VersionDomain { get; set; }

        /// <summary>
        /// If true, the associated type will not be serialized and will not be included in any generated CIP4 serializer
        /// </summary>
        public bool DontSerialize { get; set; }

        public CIP4ItemAttribute()
        {
        }
        public CIP4ItemAttribute(string collectionExternalID)
        {
            Collection = collectionExternalID;
        }
        public CIP4ItemAttribute(string collectionExternalID, bool addAllProperties)
        {
            Collection = collectionExternalID;
            AddAllProperties = addAllProperties;
        }
        public CIP4ItemAttribute(bool addAllProperties)
        {
            Collection = string.Empty;
            AddAllProperties = addAllProperties;
        }
        public CIP4ItemAttribute(string collectionExternalID, string actualName)
        {
            Collection = collectionExternalID;
            ActualName = actualName;
        }
    }

    public enum DefaultIsEnum
    {
        IsNotSpecified,
        IsTrue,
        IsFalse
    }
}